package com._520it.smis.web.servlert;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com._520it.smis.dao.IStudentDao;
import com._520it.smis.dao.impl.StudentDaoImpl;
import com._520it.smis.domain.Student;

@WebServlet("/student/edit")
public class EditStudentServlet extends HttpServlet {
	
private static final long serialVersionUID = 1L;
	
	private IStudentDao dao;
	
	@Override
	public void init() throws ServletException {
		dao = new StudentDaoImpl();
	}
	
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		String sId = req.getParameter("id");
		if (sId != null && !"".equals(sId)) {
			Long id = Long.valueOf(sId);
			Student stu = dao.get(id);
			if (stu != null) {
				req.setAttribute("stu", stu);
			}
		}
		req.getRequestDispatcher("/WEB-INF/views/student/edit.jsp").forward(req, resp);
		System.out.println("edit come");
	}

}
